package ik.xcj.hostpital.manage.controller;

import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import ik.xcj.hostpital.manage.pojo.vo.HospitalVO;
import ik.xcj.hostpital.manage.service.IHospitalService;
import ik.xcj.hostpital.manage.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/hospital")
@Api(tags = "医院模块")
@RestController
public class HospitalController {
    @Autowired
    IHospitalService iHospitalService;

    // http://localhost:9080/hospital/deleteById
    @ApiOperation("根据id删除医院详情")
    @ApiOperationSupport(order = 210)
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, example = "9527", dataType = "long")
    public JsonResult<Void> deleteById(@Range(min = 1, max = 1000000, message = "删除相册失败，相册ID非法！")
                                       @PathVariable Integer id){
        iHospitalService.delete(id);
        return JsonResult.ok();
    }


    // http://localhost:9080/hospital/xxxx
    @ApiOperation("根据id查询医院详情")
    @ApiOperationSupport(order = 410)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<HospitalVO> selectById(@Range(min = 1, max = 1000000, message = "查询相册详情失败，相册ID非法！")
                                   @PathVariable Integer id){
        HospitalVO hospital = iHospitalService.selectById(id);
        return JsonResult.ok(hospital);
    }

    // http://localhost:9080/hospital
    @ApiOperation("查询医院列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("/page")
    public JsonResult<PageInfo<HospitalVO>> list(Integer page,Integer pageSize){
        PageInfo<HospitalVO> list = iHospitalService.list(page, pageSize);
        return JsonResult.ok(list);
    }
}
